package com.itheima.web.controller.stat;

import com.alibaba.dubbo.config.annotation.Reference;
import com.itheima.service.StatService;
import com.itheima.web.controller.BaseController;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;
import java.util.Map;
import java.util.Objects;

@Controller
@RequestMapping(value = "/stat")
public class StatController extends BaseController {

    @Reference
    private StatService statService;

    @RequestMapping(value = "/toCharts")
    public String toCharts(String chartsType) {
        if (Objects.equals(chartsType, "factory")) {
            return "stat/stat-factory";
        } else if (Objects.equals(chartsType, "sell")) {
            return "stat/stat-sell";
        } else if (Objects.equals(chartsType, "online")) {
            return "stat/stat-online";
        } else {
            return "error";
        }
    }
    @RequestMapping(value = "/getFactoryData", name = "查看厂家销售数据")
    @ResponseBody
    public List<Map> getFactoryData() {
        return statService.getFactoryData(companyId);
    }

    @RequestMapping(value = "/getSellData", name = "查看产品销售排行")
    @ResponseBody
    public List<Map> getSellData() {
        return statService.getSellData(companyId);
    }

    @RequestMapping(value = "/getOnlineData", name = "查看系统访问压力")
    @ResponseBody
    public List<Map> getOnlineData() {
        return statService.getOnlineData(companyId);
    }
}
